package com.poetry.controller.user;

import com.poetry.domain.dto.QuizDTO;
import com.poetry.domain.dto.TranslationDTO;
import com.poetry.domain.po.QuizList;
import com.poetry.exception.BasePage;
import com.poetry.exception.R;
import com.poetry.service.IQuizListService;
import com.poetry.service.IQuizService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("/quiz")
@Tag(name = "题目管理模块")
public class QuizController {
    @Resource
    private IQuizService quizService;
    @Resource
    private IQuizListService quizListService;

    @PostMapping("/generate/{poemId}")
    @Operation(summary = "生成题目")
    public R<QuizDTO> generateQuiz(@PathVariable("poemId") Integer poemId, @RequestParam Integer difficulty) {
        return quizService.generateQuiz(poemId, difficulty);
    }

    @PostMapping("/check_answer")
    @Operation(summary = "检查回答")
    public R<QuizDTO> checkAnswer(@RequestParam Integer quizId, @RequestParam String answer) {
        return quizService.checkAnswer(quizId, answer);
    }

    @PostMapping("/add_quiz_list")
    @Operation(summary = "添加背诵清单")
    public R<String> addQuizList(@RequestParam Integer poemId) {
        return quizListService.addQuizList(poemId);
    }

    @DeleteMapping("/delete_quiz_list")
    @Operation(summary = "移除清单中诗词")
    public R<String> deleteQuizList(@RequestParam Integer quizId) {
        return quizListService.deleteQuizList(quizId);
    }

    @PostMapping("/get_quiz_list")
    @Operation(summary = "获取背诵列表")
    public R<List<QuizList>> getQuizList(@RequestBody BasePage basePage) {
        return quizListService.getQuizList(basePage);
    }

    @PostMapping("/translation/{poemId}")
    @Operation(summary = "生成翻译练习")
    public R<QuizDTO> generateTranslation(@PathVariable("poemId") Integer poemId) {
        return quizService.generateTranslation(poemId);
    }

    @PostMapping("/evaluate/{quizId}")
    @Operation(summary = "翻译评分")
    public R<TranslationDTO> evaluateTranslation(@PathVariable("quizId") Integer quizId, @RequestParam String translation) {
        return quizService.evaluateTranslation(quizId, translation);
    }
}
